package com.cpecc.dao.system;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.system.ToDo;
import com.cpecc.model.system.User;
import com.cpecc.model.wuzi.BaoFei;
import com.cpecc.model.wuzi.ShenQing;
import com.cpecc.model.wuzi.WeiXiu;
import com.cpecc.model.wuzi.WuZi;
import com.cpecc.model.wuzi.YiJiao;

@Repository
public class ToDoDao {

	@Resource
	private SessionFactory sessionFactory;
	
	public void save(ToDo toDo){
		Session session=sessionFactory.getCurrentSession();
		session.save(toDo);
		session.flush();
	}	
	
	public void deleteList(ShenQing shenQing){
		String hql="delete ToDo t where t.shenQing.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, shenQing.getId());
		query.executeUpdate();
	}
	
	public void deleteListSQ(ShenQing shenQing){
		String hql="delete ToDo t where t.shenQing.id=?";
		Session session=sessionFactory.openSession();
		Query query=session.createQuery(hql);
		query.setString(0, shenQing.getId());
		query.executeUpdate();
		session.close();
	}
	
	public void deleteList(YiJiao yiJiao){
		String hql="delete ToDo t where t.yiJiao.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, yiJiao.getId());
		query.executeUpdate();
	}
	
	public void deleteList(WeiXiu weiXiu){
		String hql="delete ToDo t where t.weiXiu.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, weiXiu.getId());
		query.executeUpdate();
	}
	
	public void deleteList(BaoFei baoFei){
		String hql="delete ToDo t where t.baoFei.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, baoFei.getId());
		query.executeUpdate();
	}
	
	public void deleteList(WuZi wuZi){
		String hql="delete ToDo t where t.wuZi.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, wuZi.getId());
		query.executeUpdate();
	}
	
	public void deleteList(String xinRenId){
		String hql="delete ToDo t where t.xinRenId=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, xinRenId);
		query.executeUpdate();
	}
	
	public void delete(ShenQing shenQing,User user){
		String hql="delete ToDo t where t.shenQing.id=? and t.user.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, shenQing.getId());
		query.setString(1, user.getId());
		query.executeUpdate();
	}
	
	public void delete(BaoFei baoFei,User user){
		String hql="delete ToDo t where t.baoFei.id=? and t.user.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, baoFei.getId());
		query.setString(1, user.getId());
		query.executeUpdate();
	}
	
	public void save1(ToDo toDo){
		Session session=sessionFactory.openSession();
		session.save(toDo);
		session.flush();
		session.close();
	}
}
